package com.example.myprojectoffeixue;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
//import de.tavendo.autobahn.WebSocketConnection;

public class HWadapter extends BaseAdapter {
    int flag;
    private ArrayList<HongWaiSB> d;
    private LayoutInflater layoutInflater;
    private Context context;

    public HWadapter(ArrayList<HongWaiSB> d, Context context, int flag) {
        super();
        this.d = d;
        this.context = context;
        this.flag = flag;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return d.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return d.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder h = null;

        if (convertView == null) {
            h = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_hongwai, null);
            h.tv = (TextView) convertView.findViewById(R.id.tv_itemhongwai);
            h.iv = (ImageView) convertView.findViewById(R.id.iv_shebei);
            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }

        if (flag == 1) {
            h.tv.setText(d.get(position).name);
            if ("00".equals(d.get(position).kind)) {
                //h.iv.setImageResource(R.drawable.);
            } else if ("01".equals(d.get(position).kind)) {
                //h.iv.setImageResource();
            } else if ("02".equals(d.get(position).kind)) {
                h.iv.setImageResource(R.drawable.jdh);
            } else if ("03".equals(d.get(position).kind)) {
                //h.iv.setImageResource();
            } else if ("04".equals(d.get(position).kind)) {
                h.iv.setImageResource(R.drawable.dianshi);
            } else if ("05".equals(d.get(position).kind)) {
                h.iv.setImageResource(R.drawable.jdh);
            } else if ("06".equals(d.get(position).kind)) {
                h.iv.setImageResource(R.drawable.zykt);
            }
        } else if (flag == 2) {
            SbXingHaoActivity jx = (SbXingHaoActivity) context;
            MyApplication m = (MyApplication) jx.getApplication();
            h.tv.setText(d.get(position).company);
            if ("02".equals(m.type)) {
                h.iv.setImageResource(R.drawable.jdh);
            } else if ("04".equals(m.type)) {
                h.iv.setImageResource(R.drawable.dianshi);
            } else if ("05".equals(m.type)) {

                h.iv.setImageResource(R.drawable.jdh);

            } else if ("06".equals(m.type)) {

                h.iv.setImageResource(R.drawable.zykt);

            }

        } else {
            JuTixinghaoActivity jx = (JuTixinghaoActivity) context;
            MyApplication m = (MyApplication) jx.getApplication();
            if ("02".equals(m.type)) {

                h.iv.setImageResource(R.drawable.jdh);
            } else if ("04".equals(m.type)) {
                h.iv.setImageResource(R.drawable.dianshi);
            } else if ("05".equals(m.type)) {

                h.iv.setImageResource(R.drawable.jdh);

            } else if ("06".equals(m.type)) {

                h.iv.setImageResource(R.drawable.zykt);
            }


            h.tv.setText(d.get(position).model);
        }

        return convertView;
    }


    class ViewHolder {

        TextView tv;
        ImageView iv;


    }


}